Initializing list of variables

Initializing list of variables

am 11.12.2008 17:28:38 von Deane.Rothenmaier

This is a multipart message in MIME format.
--===============0453086026==
Content-Type: multipart/alternative;
boundary="=_alternative 005A89388625751C_="

This is a multipart message in MIME format.
--=_alternative 005A89388625751C_=
Content-Type: text/plain; charset="US-ASCII"

Gurus,

I'm almost ashamed to have to post this, because I know this is a newbie
question, and I'm not really one of those any more, but I'm drawing a
blank. Isn't there an easier way to initialize a list of variables, to a
common value, than this:

my ($a, $b, $c, $d, $e, $f) = ('init', 'init', 'init', 'init', 'init',
'init');

I'm *sure* I've seen this done using map, but, like I said, every trip to
the well yields an empty bucket--except for the no-brainer line above.

TIA, and PLEASE try not to laugh too loud...

Deane Rothenmaier
Programmer/Analyst
Walgreens Corp.
224-542-5150

The chief cause of problems is solutions. - Eric Sevareid
--=_alternative 005A89388625751C_=
Content-Type: text/html; charset="US-ASCII"



Gurus,



I'm almost ashamed to have to post this,
because I know this is a newbie question, and I'm not really one of those
any more, but I'm drawing a blank.  Isn't there an easier way to initialize
a list of variables, to a common value, than this:




my ($a, $b, $c, $d, $e, $f) = ('init',
'init', 'init', 'init', 'init', 'init');




I'm *sure* I've seen this done using
map, but, like I said, every trip to the well yields an empty bucket--except
for the no-brainer line above.




TIA, and PLEASE try not to laugh too
loud...




Deane Rothenmaier

Programmer/Analyst

Walgreens Corp.

224-542-5150



The chief cause of problems is solutions. - Eric Sevareid

--=_alternative 005A89388625751C_=--


--===============0453086026==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0453086026==--

RE: Initializing list of variables

am 11.12.2008 17:39:09 von Brian Raven

From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of
Deane.Rothenmaier@walgreens.com
Sent: 11 December 2008 16:29
To: activeperl@listserv.ActiveState.com
Subject: Initializing list of variables

> Gurus,
>
> I'm almost ashamed to have to post this, because I know this is a
newbie question, and I'm not really one of
> those any more, but I'm drawing a blank. Isn't there an easier way to
initialize a list of variables, to a
> common value, than this:
>
> my ($a, $b, $c, $d, $e, $f) = ('init', 'init', 'init', 'init', 'init',
'init');

I'm not sure how I would do it with map, but the following is likely to
be simpler.

my ($a, $b, $c, $d, $e, $f) = ('init') x 6;

See 'Multiplicative Operators' in 'perldoc perlop' for more details.

>
> I'm *sure* I've seen this done using map, but, like I said, every trip
to the well yields an empty bucket--
> except for the no-brainer line above.
>
> TIA, and PLEASE try not to laugh too loud...

No more than a gentle chuckle. Promise.

HTH

--
Brian Raven

------------------------------------------------------------ -----------------------------------------------
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Initializing list of variables

am 11.12.2008 17:43:10 von Gaurav Vaidya

Hi Deane,

2008/12/12 :
> my ($a, $b, $c, $d, $e, $f) = ('init', 'init', 'init', 'init', 'init', 'init');

I thought "hmm, you want to repeat a value ... what about the
repetition operator?". Just for a lark, I tried:
> perl -e 'my ($a, $b, $c) = ('init') x 3; print "$a:$b:$c\n";'

And it worked! Reading `perlop`, I see this is entirely expected, but
it took me by surprise. I was just too used to 'x' being a
string-related operator, and IMHO this takes DWIM to new heights.

Ah, well - learn something new every day!

cheers,
Gaurav
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Initializing list of variables

am 11.12.2008 17:48:05 von Phil Rafferty

On Dec 11, 2008, at 11:39 AM, Brian Raven wrote:

From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of
Deane.Rothenmaier@walgreens.com
Sent: 11 December 2008 16:29
To: activeperl@listserv.ActiveState.com
Subject: Initializing list of variables

> Gurus,
>
> I'm almost ashamed to have to post this, because I know this is a
newbie question, and I'm not really one of
> those any more, but I'm drawing a blank. Isn't there an easier way to
initialize a list of variables, to a
> common value, than this:
>
> my ($a, $b, $c, $d, $e, $f) = ('init', 'init', 'init', 'init', 'init',
'init');

I'm not sure how I would do it with map, but the following is likely to
be simpler.

my ($a, $b, $c, $d, $e, $f) = ('init') x 6;

See 'Multiplicative Operators' in 'perldoc perlop' for more details.

>
> I'm *sure* I've seen this done using map, but, like I said, every trip
to the well yields an empty bucket--
> except for the no-brainer line above.
>
> TIA, and PLEASE try not to laugh too loud...

No more than a gentle chuckle. Promise.

HTH

--
Brian Raven

This one also works - TMTOWTDI

my ($a,$b,$c) = map { 'init' } 1..3;

Phil Rafferty

------------------------------------------------------------ -----------------------------------------------
This e-mail may contain confidential and/or privileged information. If
you are not the intended recipient or have received this e-mail in
error, please advise the sender immediately by reply e-mail and delete
this message and any attachments without retaining a copy. Any
unauthorised copying, disclosure or distribution of the material in
this e-mail is strictly forbidden.


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Initializing list of variables

am 11.12.2008 17:49:31 von Andy_Bach

Yeah, not sure 'map' is going to give you a trick here, unless there is
some other source that has the list of init values. You could try:
map { $$_ = 'init' } qw(a b c d e f);

but that's just wrong - map in a void context *and* the ref var name
thingee (
Can't use string ("a") as a SCALAR ref while "strict refs" ...
) Oh, were you thinking:

my ($a, $b, $c,$d, $e, $f);
$a = $b = $c =$d = $e = $f = 'init';

a
-------------------
Andy Bach
Systems Mangler
Internet: andy_bach@wiwb.uscourts.gov
Voice: (608) 261-5738 Fax: 264-5932

It's is not its, it isn't ain't, and it's it's, not its, if you mean it
is. If you don't, it's its. Then too, it's hers. It isn't her's.
It isn't our's either. It's ours, and likewise yours and theirs.
-- Oxford University Press, Edpress News

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Initializing list of variables

am 11.12.2008 17:52:15 von Williamawalters

--===============0915521439==
Content-Type: multipart/alternative;
boundary="-----------------------------1229014335"


-------------------------------1229014335
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit


hi deane --

In a message dated 12/11/2008 11:29:11 A.M. Eastern Standard Time,
Deane.Rothenmaier@walgreens.com writes:

> my ($a, $b, $c, $d, $e, $f) = ('init', 'init', 'init', 'init', 'init',
'init');


to init all to the same value without knowing in advance the number
of variables, how 'bout

>perl -wMstrict -le
"$_ = 'init' for my ($a, $b, $c);
print $c;
"
init



**************Make your life easier with all your friends, email, and
favorite sites in one place. Try it now.
(http://www.aol.com/?optin=new-dp&icid=aolcom40vanity&ncid=e mlcntaolcom00000010)

-------------------------------1229014335
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable





Arial"=20
bottomMargin=3D7 leftMargin=3D7 topMargin=3D7 rightMargin=3D7> e_document=20
face=3DArial color=3D#000000 size=3D2>


hi deane --  

 

In a message dated 12/11/2008 11:29:11 A.M. Eastern Standard Time,=20
Deane.Rothenmaier@walgreens.com writes:

 

> my ($a, $b, $c, $d, $e, $f) =3D ('init', 'init', 'init', 'init', '=
init',=20
'init');  

 

 

to init all to the same value without knowing in advance the number IV>
of variables, how 'bout  

 

>perl -wMstrict -le
"$_ =3D 'init' for my ($a, $b, $c);
 =
print=20
$c;
"
init

 



=3D"3899a1b85a0477f80eb1e3c72ecff2e"> al 10pt ARIAL, SAN-SERIF;">
Make your life eas=
ier with all your friends, email, and favorite sites in one place. =3D"http://www.aol.com/?optin=3Dnew-dp&icid=3Daolcom40vanity &ncid=3Demlcntao=
lcom00000010">Try it now
.


-------------------------------1229014335--

--===============0915521439==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0915521439==--

Re: Initializing list of variables

am 12.12.2008 01:37:04 von Jenda Krynicky

From: Deane.Rothenmaier@walgreens.com
> I'm almost ashamed to have to post this, because I know this is a newbie
> question, and I'm not really one of those any more, but I'm drawing a
> blank. Isn't there an easier way to initialize a list of variables, to a
> common value, than this:
>
> my ($a, $b, $c, $d, $e, $f) = ('init', 'init', 'init', 'init', 'init',
> 'init');

A list of variables should most probably be a list variable. OK, an
array variable, but that doesn't sound as nice. Or a hash. But most
likely you'll find yourself wanting to do more things to all those
variables later. Which is trivial if it's a single variable
containing several values, but tedious if its several variables.

Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs